﻿using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Collections.Generic;
using System;
using System.IO;
using System.IO.Compression;

namespace WebPALTT.Lib
{
    // A KeyValuePair substitue as KeyValuePair is readonly in property grids.
    public class KVP_Type<TKey, TVal>
    {
        TKey key;
        TVal val;

        [DescriptionAttribute("Key")]
        public TKey Key { get { return key; } set { key = value; } }
        [DescriptionAttribute("Value")]
        public TVal Value { get { return val; } set { val = value; } }
        [BrowsableAttribute(false)]
        public KeyValuePair<TKey, TVal> KeyValuePair { get { return new KeyValuePair<TKey, TVal>(this.key, this.val); } }

        public KVP_Type(TKey key, TVal val)
        {
            this.key = key;
            this.val = val;
        }

        public KVP_Type(KeyValuePair<TKey, TVal> value)
        {
            this.key = value.Key;
            this.val = value.Value;
        }

        public override string ToString()
        {
            return "[" + key.ToString() + " , " + val.ToString() + "]";
        }
    }

    public static class GZipCompression
    {
        public static string Decompress(Stream s)
        {
            using (GZipStream decompress = new GZipStream(s, CompressionMode.Decompress))
            {
                return new StreamReader(decompress).ReadToEnd();
            }
        }
    }
}
